package com.shopyourstyle.item;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.Log;

public class MagItem {
	private String _resName;
	private Drawable _pic;
	private String[] _textLine = new String[3];
	private static final String PACKAGE_NAME = "ShopStyle.htc" ;
	private Context _context;
	private int _height;
	private int _width;
	private Paint _textPaint = new Paint();
	private int _textHeight;
	
	public MagItem(Context context, String pictureName, String textLine1, String textLine2, String textLine3) {
		_textPaint.setColor( Color.GREEN );
		_textHeight = (int) ( _textPaint.getTextSize() );
		
		_context = context;
		_resName = pictureName;
		Log.e ("MagItem", "Allocating resource : " + _resName);
		_textLine[0] = textLine1;
		_textLine[1] = textLine2;
		_textLine[2] = textLine3;
		
		
		//_pic = this.getResources().getDrawable(R.drawable.pig);
		
		int resID = _context.getResources().getIdentifier(_resName , "drawable", _context.getPackageName() );
		_pic = _context.getResources().getDrawable( resID );
		if (_pic!=null) {
			Log.e("MagItem" , "Allocated resource [" + _resName + "]" + _pic.toString());
			_height = _pic.getIntrinsicHeight();
			_width = _pic.getIntrinsicWidth();
			Log.e("MagItem" , "  H[" + _height + "] W[" + _width + "]" );
			
		}
			
		
		//getResources().getIdentifier("bug", "drawable", "org.anddev.android.testproject")
		//pic1 = this.getResources().getDrawable(R.drawable.pig);
	}
	public void drawOnCanvas(Canvas c, int x,int y , int alpha) {
		if (c==null) return ;
		
		_pic.setBounds(x, y, x+_width , y+ _height);
		_pic.setAlpha(alpha);
		_pic.draw(c);
		//Draw Lines

		_textPaint.setAlpha(alpha);
		for (int i=0;i<3;++i) {
			c.drawText( _textLine[0] , x , y + _height + i*_textHeight + 5 , _textPaint); 

		}
		/*
		int textY = (int)((15 + 20 * ptr) * scale);
		c.drawText("id" + ptr + "=" + id, width - 55 * scale, textY, textPaint);
		*/
		
	}

}
